package com.learning.demos.jvmgc;

import java.lang.ref.WeakReference;

/**
 * @author adolphw
 *
 * 只要回收就都回收
 */
public class WeakReferenceDemo {
    public static void main(String[] args) {
        Object o1 = new Object();

        WeakReference<Object> weakReference = new WeakReference<Object>(o1);

        System.out.println(o1);
        System.out.println(weakReference.get());

        o1 = null;
        System.gc();
        System.out.println("================");

        System.out.println(o1);
        System.out.println(weakReference.get());

    }
}
